#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n; long long cost; cin >> n >> cost;
  multiset<pair<int, int>> s;
  while(n--) {
    int a, b, c; cin >> a >> b >> c;
    s.emplace(a, c);
    s.emplace(b + 1, -c);
  }
  int prev = 0;
  long long now = 0, ans = 0;
  while(!s.empty()) {
    auto [day, c] = *begin(s);
    ans += min(now, cost) * (day - prev);
    prev = day;
    now += c;
    s.erase(begin(s));
    while(!s.empty()) {
      auto [day2, c2] = *begin(s);
      if(day != day2) break;
      now += c2;
      s.erase(begin(s));
    }
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
